package com.company.cloud.common.context;

import java.util.HashMap;
import java.util.Map;

public class SaasContextOperateByThreadLocal implements ISaasContextOperate {

	private static final ThreadLocal<Map<Object, Object>> threadContext = 
			new SaasContextOperateByThreadLocal.MapThreadLocal();
	
	
	private static class MapThreadLocal extends ThreadLocal<Map<Object, Object>> {
		private MapThreadLocal() {
		}
		protected Map<Object, Object> initialValue() {
			return new HashMap<Object, Object>(){
				@Override
				public Object put(Object key, Object value) {
					return super.put(key, value);
				}
			};
		}
	}
	

	public SaasContextOperateByThreadLocal() {
	}
	
    public Map<Object, Object> getSaasContext() {
        return (Map)threadContext.get();
    }
	
	@Override
	public String getUserData(String key) {
		 return (String)this.getSaasContext().get(key);
	}

	@Override
	public String putUserData(String key, String value) {
		 return (String)this.getSaasContext().put(key, value);
	}

	@Override
	public String removeUserData(String key) {
		 return (String)this.getSaasContext().remove(key);
	}
	
	




}
